/*
 * @lc app=leetcode.cn id=937 lang=javascript
 *
 * [937] 重新排列日志文件
 */

// @lc code=start
/**
 * @param {string[]} logs
 * @return {string[]}
 */
var reorderLogFiles = function (logs) {
  return logs
    .filter(log => /^[a-zA-Z]+$/.test(log.split(' ')[1]))
    .sort((a, b) => {
      let [signA, ...contentA] = a.split(' ');
      let [signB, ...contentB] = b.split(' ');
      if (contentA.join(' ') === contentB.join(' ')) {
        return signA > signB ? 1 : -1;
      } else {
        return contentA.join(' ') > contentB.join(' ') ? 1 : -1;
      }
    })
    .concat(
      logs
        .filter(log => /^[0-9]+$/.test(log.split(' ')[1]))
    )
};
// @lc code=end

